<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>math随机数</title>
    <script>
        // random  返回一个随机的小数 0 <= x <1
        console.log(Math.random());
        // 想得到两个数之间的随机整数 并且 包含这两个整数
        function getRandom(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }
        console.log(getRandom(1, 10));
        //随机点名
        var arr = ['张三', '张三疯', '了事', 'fa', 'sdgf']
        console.log(arr[getRandom(0, arr.length - 1)]);

        //
        var random = getRandom(1, 10);
        while (true) {
            var num = prompt('猜一猜数字大小')
            if (num > random) {
                alert('你猜大了');
            }
            else if (num < random) {
                alert('你猜小了');
            }
            else {
                alert('你真棒')
                break
            }
        }
    </script>
</head>

<body>

</body>

</html>